//? 超时重新请求 到达一定次数后输出缓存内容


Promise.retry = (callback, retryTime) => {
    return new Promise((resolve, reject) => {
        //? 这里实现了递归then
        Promise.resolve(callback()).then((value) => {
            resolve(value)
        }, (reason) => {
            //? 次数超了 直接reject
            --retryTime
            if (!retryTime) reject(reason)
            else{
                //? 重试 这里也在递归then
                Promise.retry(callback, retryTime).then(resolve, reject)
            }
        })
    })
}
let count = 0
Promise.retry(() => {
    console.log(++count)
    return count === 4 ? Promise.resolve('success') : Promise.reject('failed')
}, 3).then((value) => console.log(value), (err) => console.log(err))
